#pragma once

#include <string>

namespace kernel {
namespace task {

/**
 * @brief 任务链执行状态枚举
 * @details 参考三方代码 taskchain.cpp 的状态管理
 */
enum class TaskChainStatus {
    Ok,                 // 正常执行
    KeepOn,             // 任务保持（暂不继续）
    Suspend,            // 挂起等待（有计数器）
    Timeout,            // 监控超时但不中止任务
    Error,              // 执行错误
    Recalculation,      // 路径重计算（需要动态插入任务）
    DispatcherMove      // 移动到管控区外站点
};

/**
 * @brief 任务状态枚举
 */
enum class TaskStatus {
    Pending,      // 等待执行
    Running,      // 执行中
    Paused,       // 暂停
    Completed,    // 完成
    Failed,       // 失败
    Cancelled     // 取消
};

/**
 * @brief 任务类型枚举
 */
enum class TaskType {
    Move,         // 移动任务
    Jack,         // 顶升任务
    Charge,       // 充电任务
    Park,         // 泊车任务
    Lift,         // 电梯任务
    Custom        // 自定义任务
};

/**
 * @brief 子任务阶段枚举
 */
enum class TaskStage {
    Init,         // 初始化阶段
    Running,      // 运行阶段
    Cleanup,      // 清理阶段
    Finished      // 完成阶段
};

/**
 * @brief 任务优先级
 */
enum class TaskPriority {
    Low = 0,
    Normal = 1,
    High = 2,
    Critical = 3
};

/**
 * @brief 将任务链状态转换为字符串
 */
inline std::string taskChainStatusToString(TaskChainStatus status) {
    switch (status) {
        case TaskChainStatus::Ok:              return "Ok";
        case TaskChainStatus::KeepOn:          return "KeepOn";
        case TaskChainStatus::Suspend:         return "Suspend";
        case TaskChainStatus::Timeout:         return "Timeout";
        case TaskChainStatus::Error:           return "Error";
        case TaskChainStatus::Recalculation:   return "Recalculation";
        case TaskChainStatus::DispatcherMove:  return "DispatcherMove";
        default: return "Unknown";
    }
}

/**
 * @brief 将任务状态转换为字符串
 */
inline std::string taskStatusToString(TaskStatus status) {
    switch (status) {
        case TaskStatus::Pending:   return "Pending";
        case TaskStatus::Running:   return "Running";
        case TaskStatus::Paused:    return "Paused";
        case TaskStatus::Completed: return "Completed";
        case TaskStatus::Failed:    return "Failed";
        case TaskStatus::Cancelled: return "Cancelled";
        default: return "Unknown";
    }
}

/**
 * @brief 将任务类型转换为字符串
 */
inline std::string taskTypeToString(TaskType type) {
    switch (type) {
        case TaskType::Move:   return "Move";
        case TaskType::Jack:   return "Jack";
        case TaskType::Charge: return "Charge";
        case TaskType::Park:   return "Park";
        case TaskType::Lift:   return "Lift";
        case TaskType::Custom: return "Custom";
        default: return "Unknown";
    }
}

/**
 * @brief 将任务阶段转换为字符串
 */
inline std::string taskStageToString(TaskStage stage) {
    switch (stage) {
        case TaskStage::Init:     return "Init";
        case TaskStage::Running:  return "Running";
        case TaskStage::Cleanup:  return "Cleanup";
        case TaskStage::Finished: return "Finished";
        default: return "Unknown";
    }
}

} // namespace task
} // namespace kernel
